Loop_Practise_Que_01

Home / Java Practice Question / Loop_Practise_Que_01

Loop_Practise_Que_01


Write a Java program to calculate factorial of a number.


Program: - 



public class Loop {

 public static int factorial(int n){
if(n==0 || n==1){
return 1;
}
int ans=n*factorial(n-1);
return ans;
}

}